<?php
namespace app\index\controller;
use think\Request;
use think\Db;

class News extends Common
{
	public $req;
	function __construct() {
		parent::__construct();
		$this->req = Request::instance();

        // 判断当前控制器, 使相应导航高亮
		$con = __CLASS__;
        $arr = explode('\\', $con);
        $this->assign('_class', strtolower($arr[3]));

        $nav = 'news';
        $this->assign('nav', $nav);
	}

	/**
	 * 某分类下新闻列表
	 */
	public function newsList()
	{
		if (isset($_GET['id'])) {
			// 分类id
			$cid = input('get.id');

			// 分类信息
			$cInfo = Db::table('news_categorys')->where('id='.$cid)->find();

			// 此分类下新闻
			$newsList = Db::table('news')
				->where([ 'nid'	 => $cid, 'status' => '1' ])
				->order('publish_at desc')
				->select();
			
		} else {
			$cInfo['name'] = '新闻动态';
			$newsList = Db::table('news')
				->where(['status' => '1' ])
				->order('publish_at desc')
				->select();
		}
		
		$this->assign('cInfo', $cInfo);
		$this->assign('newsList', $newsList);
		return $this->fetch('index/newsdt');
	}

	/**
	 * 新闻详情
	 */
	public function newsdet()
	{
		// 新闻id
		$id = input('get.id');

		// 分类信息
		$nInfo = Db::table('news')
			->field('id, nid as cid, title, auth, content, publish_at as publish_time')
			->where('id='.$id)
			->find();
		$this->assign('article_info', $nInfo);

		return $this->fetch('index/xiangqing');
	}

	/**
	 * 新闻模块(新闻的分类列表)
	 */
	/*public function newscat()
	{
		// 分类信息
		$clist = Db::table('news_categorys')->select();
		$this->assign('clist', $clist);

		return $this->fetch('index/newsmodule');
	}*/
}
